const state = {
    CustomDrawer: false,
    content: 0,
    type: '',
    keyArray: [],
    activeObj: null,
    callbackEvent: null,
};
const getters = {};
const mutations = {};
const actions = {
    getRenderData(context) {
        // action=> 获取全部Key值
        window.action.key.getAll().then((res) => {
            if (res) {
                for (let i = 0; i < res.length; i++) {
                    const element = res[i];
                    element.ping = '';
                    element.edit = false;
                    element.editKey = '';
                };
                context.state.keyArray = res;
            };
        });
    },
    creatKey(context, param) {
        window.action.key.creat(param.key).then((res) => {
            if (res) {
                param.callback();
                context.dispatch('getRenderData');
            };
        });
    },
    updateKey(context, param) {
        window.action.key.update(param).then((res) => {
            if (res) {
                context.dispatch('getRenderData');
            };
        });
    },
    deleteKey(context, param) {
        window.action.key.delete(param).then((res) => {
            if (res) {
                context.dispatch('getRenderData');
            };
        });
    },
    showCustomDrawer(context, option) {
        context.state.activeObj = option.activeObj;
        context.state.type = option.type;
        context.state.callbackEvent = option.callbackEvent || null;
        context.state.CustomDrawer = false;
        context.state.CustomDrawer = true;
    },
    colseCustomDrawer(context) {
        context.state.CustomDrawer = false;
        context.state.callbackEvent = null;
    },
    changeCustom(context) {
        context.state.content++;
    },


};

export default {
    namespaced: true,
    state,
    getters,
    mutations,
    actions
}